package jee.boot.module.main.service;


import jee.boot.common.basic.CrudService;
import jee.boot.module.main.dao.DemoChildDao;
import jee.boot.module.main.dao.DemoMainDao;
import jee.boot.module.main.entity.DemoChild;
import jee.boot.module.main.entity.DemoMain;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 示例-主从表操作(主表)Service
 * @author 
 * @version 2019-06-19
 */
@Service
public class DemoMainService extends CrudService<DemoMainDao, DemoMain> {

	@Autowired
	private DemoChildDao demoChildDao;
	
	public DemoMain get(DemoMain entity) {
		DemoMain demoMain = super.get(entity);
		demoMain.setDemoChildList(super.getOneToMany(demoChildDao, entity, new DemoChild(), "head_id"));
		return demoMain;
	}
	
	
	public void save(DemoMain entity) {
		super.save(entity);
		super.saveOneToMany(demoChildDao,entity,entity.getDemoChildList());
	}
	public void update(DemoMain entity) {
		super.update(entity);
		super.updateOneToMany(demoChildDao,entity,new DemoChild(),entity.getDemoChildList());

	}
	public void delete(DemoMain entity) {
		super.delete(entity);
		demoChildDao.delete(new DemoChild(entity));
	}
	
}